package com.fmdj.mis.api.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.fmdj.common.util.CommonResult;
import com.fmdj.common.util.PageUtils;
import com.fmdj.mis.api.controller.form.DeleteVoucherByIdsForm;
import com.fmdj.mis.api.controller.form.InsertVoucherForm;
import com.fmdj.mis.api.controller.form.SearchVoucherByPageForm;
import com.fmdj.mis.api.controller.form.UpdateVoucherStatusForm;
import com.fmdj.mis.api.feign.VhrServiceApi;
import com.fmdj.mis.api.service.VoucherService;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;

@Service
public class VoucherServiceImpl implements VoucherService {
    @Autowired
    private VhrServiceApi vhrServiceApi;

    @Override
    public int insertVoucher(InsertVoucherForm form) {
        CommonResult r = vhrServiceApi.insertVoucher(form);
        int rows = (int) r.get(CommonResult.RETURN_ROW);
        return rows;
    }

    @Override
    public PageUtils searchVoucherByPage(SearchVoucherByPageForm form) {
        CommonResult r = vhrServiceApi.searchVoucherByPage(form);
        HashMap hashMap = (HashMap) r.get(CommonResult.RETURN_RESULT);
        PageUtils pageUtils = BeanUtil.toBean(hashMap, PageUtils.class);
        return pageUtils;
    }

    @Override
    @LcnTransaction
    @Transactional
    public int updateVoucherStatus(UpdateVoucherStatusForm form) {
        CommonResult r = vhrServiceApi.updateVoucherStatus(form);
        int rows = (int) r.get(CommonResult.RETURN_ROW);
        return rows;
    }

    @Override
    @LcnTransaction
    @Transactional
    public int deleteVoucherByIds(DeleteVoucherByIdsForm form) {
        CommonResult r = vhrServiceApi.deleteVoucherByIds(form);
        int rows = (int) r.get(CommonResult.RETURN_ROW);
        return rows;
    }
}
